<?php

class modify_data extends connection{
    function xoa_data(){
        $dong = $_POST['dong'];
        $query = "DELETE FROM articles WHERE id = ".$dong;
        $this->ketnoi($query);
    }
    function  them_data(){
        $title = $_POST['title'];
        $overview = $_POST['overview'];
        $body = $_POST['body'];
        $id_category = $_POST['id_category'];
        if($id_category <= 5){
        $query = 'INSERT INTO articles(title, overview, body, id_category) VALUES ("'.$title.'","'.$overview.'","'.$body.'","'.$id_category.'")';
        $this->ketnoi($query);
        }  else {
        echo 'bạn nhập id_category từ 1 đến 5';
        }
    }
    function capnhat_data(){
        $id = trim($_POST['id_update']);
        $title = trim($_POST['title_update']);
        $overview = trim($_POST['overview_update']);
        $body = trim($_POST['body_update']);
        $id_category = trim($_POST['id_category_update']);
        $qry1 = 'UPDATE articles SET ';
        $qry2 = ' WHERE id = '.$id;
        if($title != ''){
        $query = $qry1.'title = "'.$title.'" '.$qry2;
        $this->ketnoi($query);
        
        }
        if($overview != ''){
        $query1 = $qry1.'overview = "'.$overview.'" '.$qry2;
        $this->ketnoi($query1);
        
        }
        if($body != ''){
        $query2 = $qry1.'body = "'.$body.'" '.$qry2;
        $this->ketnoi($query2);
        }
        if($id_category!=''){
        $query3 = $qry1.'id_category = "'.$id_category.'" '.$qry2;
        $this->ketnoi($query3);
        }
    }
}


